-
Notifications
You must be signed in to change notification settings - Fork 2.2k
fix: resolve PrimitiveType casting for OpenAPI 3.1 schemas (#4963) #4989
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
fix: resolve PrimitiveType casting for OpenAPI 3.1 schemas (#4963) #4989
Conversation
… enum" This reverts commit 7c0a6af.
modules/swagger-jaxrs2/src/test/java/io/swagger/v3/jaxrs2/APIResponsesResourceTest.java
Outdated
Show resolved
Hide resolved
addKeys(keyClasses, NUMBER, Number.class); | ||
addKeys(keyClasses, DATE, DateStub.class); | ||
addKeys(keyClasses, DATE_TIME, java.util.Date.class); | ||
// addKeys(keyClasses, PARTIAL_TIME, java.time.LocalTime.class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove this comment
NAMES = Collections.unmodifiableMap(names); | ||
|
||
// Add "LocalTime" class mappings | ||
enablePartialTime(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is not a part of the solution to the #4963. Please consider creating a feature request for this change and describing why this change should be introduced. Some analysis would be necessary to confirm it's align with JSON Schema.
For now please remove it
} | ||
} | ||
if (StringUtils.isBlank(existingSchemaObject.get$ref()) && StringUtils.isBlank(existingSchemaObject.getType())) { | ||
boolean doesSchemaHaveTypes = existingSchemaObject.getTypes() == null || existingSchemaObject.getTypes().isEmpty(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name of the method here is misleading. It returns true when empty/ null. Please rename it
" type: object\n" + | ||
" properties:\n" + | ||
" annotated:\n" + | ||
" type: \"object\"\n" + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide at least on test with 'null' in type
Pull Request
Thank you for contributing to swagger-core!
Please fill out the following information to help us review your PR efficiently.
Description
This PR fixes an issue where
PrimitiveType
OpenAPI 3.1 schemas used in@ApiResponse
content schema implementations are incorrectly cast to type"string"
instead of properly-defined types.Problem
For each enum in
PrimitiveType
, theircreateProperty31()
method sets the value for only fieldtype
and nottypes
.Solution
Updated
createProperty31()
to set a value for fieldtypes
. A new test classAPIResponsesResourceTest
verifies that the resulting schema'stype
andtypes
field values match for each class defined in@Schema(implementation = ...)
.Relevant issue
Fixes: #4963
Type of Change
Checklist
Screenshots / Additional Context
Added files:
modules/swagger-jaxrs2/src/test/java/io/swagger/v3/jaxrs2/resources/APIResponsesResource.java
modules/swagger-jaxrs2/src/test/java/io/swagger/v3/jaxrs2/APIResponsesResourceTest.java
Affected files:
modules/swagger-core/src/main/java/io/swagger/v3/core/util/AnnotationsUtils.java
modules/swagger-core/src/main/java/io/swagger/v3/core/util/PrimitiveType.java
modules/swagger-java17-support/src/test/java/io/swagger/v3/java17/resolving/v31/ModelResolverOAS31Test.java
modules/swagger-core/src/test/java/io/swagger/v3/core/resolving/Ticket2992Test.java